package xyz.erupt.flow.service;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import xyz.erupt.flow.bean.entity.OaWorkFlowDefinition;
import xyz.erupt.flow.bean.entity.node.OaProcessNode;
import xyz.erupt.flow.data.dto.DTO_OaWorkFlowDefinition;
import xyz.erupt.flow.data.interfaces.Create;
import xyz.erupt.flow.data.interfaces.Update;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@Validated
public interface WorkFlowDefinitionService {

    /**
     * @description:更新定义
     * @author: PP
     * @date: 2024/10/20 14:33
     * @param: [entity]
     * @return: void
    **/
    @Validated(value = {Update.class})
    @Transactional(rollbackFor = Exception.class)
    void update(@Valid DTO_OaWorkFlowDefinition entity);

    /**
     * @description:创建流程
     * @author: PP
     * @date: 2024/10/20 14:33
     * @param: [groupId, formName, logo, formItems, process, settings, remark]
     * @return: void
    **/
    @Validated(value = {Create.class})
    @Transactional(rollbackFor = Exception.class)
    void create(@Valid DTO_OaWorkFlowDefinition workFlowDefinition);

    /**
     * @description:查找组的所有定义的最新版本
     * @author: PP
     * @date: 2024/10/20 14:33
     * @param: [groupId, keywords]
     * @return: java.util.List<xyz.erupt.flow.bean.entity.OaWorkFlowDefinition>
    **/
    List<OaWorkFlowDefinition> listByGroupId(@NotNull Long groupId, String keywords);

    /**
     * @description:排序
     * @author: PP
     * @date: 2024/10/20 14:33
     * @param: [defIds]
     * @return: void
    **/
    @Transactional(rollbackFor = Exception.class)
    void DefSort(@NotNull List<Long> defIds);

    /**
     * 停用流程
     * @param processKey
     */
    @Transactional(rollbackFor = Exception.class)
    void StopDef(@NotBlank String processKey);

    /**
     * 启用流程
     * @param processKey
     */
    @Transactional(rollbackFor = Exception.class)
    void StartDef(@NotBlank String processKey);

    /**
     * 删除定义,逻辑删除所有版本该流程
     * @param processKey
     */
    @Transactional(rollbackFor = Exception.class)
    void removeByProcessKey(@NotBlank String processKey);


    /**
     * 获取的为最新版本流程定义数据
     * @param processKey
     * @return
     */
    OaWorkFlowDefinition getByProcessKey(@NotBlank String processKey);

    /**
     * 通过id获取定义数据（包含历史版本数据）
     * @param id
     * @return
     */
    OaWorkFlowDefinition getById(@NotNull Long id);

    String preview(@NotNull String processKey);
}
